#include "MediaConvert.h"
#include "MediaDefine.h"

/************************* FFMpegHeader *************************/
const char *Media_TypeName(int mediaType) {
  switch (mediaType) {
    case MediaType_Video:
      return "MediaType_Video";
    case MediaType_Audio:
      return "MediaType_Audio";
    default:
      return "MediaType_None";
  }
}

const char *Media_RawTypeName(int rawType) {
  switch (rawType) {
    case MediaRawType_I420:
      return "MediaRawType_I420";
    case MediaRawType_NV12:
      return "MediaRawType_NV12";
    case MediaRawType_NV21:
      return "MediaRawType_NV21";
    case MediaRawType_S16:
      return "MediaRawType_S16";
    case MediaRawType_S16P:
      return "MediaRawType_S16P";
    default:
      return "MediaRawType_None";
  }
}


/************************* FFMpegHeader *************************/
AVPixelFormat FFMpeg_RawType2PixelFormat(int32_t rawType) {
  switch (rawType) {
    case MediaRawType_I420:
      return AV_PIX_FMT_YUV420P;
    case MediaRawType_NV12:
      return AV_PIX_FMT_NV12;
    case MediaRawType_NV21:
      return AV_PIX_FMT_NV21;
    default:
      return AV_PIX_FMT_NONE;
  }
}

int32_t FFMpeg_PixelFormat2RawType(AVPixelFormat pixelFormat) {
  switch (pixelFormat) {
    case AV_PIX_FMT_YUV420P:
      return MediaRawType_I420;
    default:
      return -1;
  }
}

AVSampleFormat FFMpeg_RawType2SampleFormat(int32_t rawType) {
  switch (rawType) {
    case MediaRawType_S16:
      return AV_SAMPLE_FMT_S16;
    case MediaRawType_S16P:
      return AV_SAMPLE_FMT_S16P;
    default:
      return AV_SAMPLE_FMT_NONE;
  }
}

int32_t FFMpeg_SampleFormat2RawType(AVSampleFormat sampleFormat) {
  switch (sampleFormat) {
    case AV_SAMPLE_FMT_S16:
      return MediaRawType_S16;
    case AV_SAMPLE_FMT_S16P:
      return MediaRawType_S16P;
    default:
      return -1;
  }
}

int32_t FFMpeg_AVMediaTypeConvert(AVMediaType mediaType) {
  switch (mediaType) {
    case AVMEDIA_TYPE_VIDEO:
      return MediaType_Video;
    case AVMEDIA_TYPE_AUDIO:
      return MediaType_Audio;
    default:
      return -1;
  }
}

AVMediaType FFMpeg_MediaTypeConvert(int32_t mediaType) {
  switch (mediaType) {
    case MediaType_Video:
      return AVMEDIA_TYPE_VIDEO;
    case MediaType_Audio:
      return AVMEDIA_TYPE_AUDIO;
    default:
      return AVMEDIA_TYPE_UNKNOWN;
  }
}